package DaoTest;


import com.alibaba.fastjson.JSON;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayHandler;
import org.apache.commons.dbutils.handlers.ArrayListHandler;
import org.junit.Test;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestEchars {
    DataSource dataSource;
    QueryRunner queryRunner;
    @Test
    public String getEhars() throws SQLException {
        dataSource = new ComboPooledDataSource();
        queryRunner = new QueryRunner(dataSource);

          Object[]objects= queryRunner.query("select count(*) from user where city='西安'", new ArrayHandler());
          Object[]objects1= queryRunner.query("select count(*) from user where city='上海'", new ArrayHandler());
          Object[]objects2= queryRunner.query("select count(*) from user where city='北京'", new ArrayHandler());
          Object[]objects3= queryRunner.query("select count(*) from user where city='深圳'", new ArrayHandler());

            Map map=new HashMap();
            map.put("xian",objects);
            map.put("shanghai",objects1);
            map.put("beijing",objects2);
            map.put("shengzheng",objects3);
            String jsonString = JSON.toJSONString(map);
        return jsonString;

    }
}
